<template>
    <div class="w100_ h100_ flex-column hidden">
        <div class="flex-row-center greycolor pd20">
            <span class="weight pointer mr30" @click="proxy.routerBackMixin()"><< 返回</span>
            <span class="">配置管理 >> 编辑配置</span>
        </div>
        <div class="flex-column w100_ flex1 hidden">
            <div class="w100_ whitebg radius10 pd20-row">
                <span class="titleLabel mb10">配置</span>
                <el-form ref="form" :model="obj.data" label-width="80px">
                    <el-form-item label="名称" prop="name" :rules="[formRulesMixin.notNull]">
                        <el-input v-model="obj.data.name" clearable autocomplete="off"></el-input>
                    </el-form-item>
                    <div class="w100_ pd10-column">
                        <!-- <span class="btn linebtn clear" @click="proxy.routerBackMixin()">取消</span> -->
                        <span class="btn sub ml30" @click.prevent="upData">保存</span>
                    </div>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, onMounted } from 'vue'
    let { proxy } = getCurrentInstance()
    const emit = defineEmits(['init', 'close']) //此处要完全对应，采用固定的update:prop属性

    let obj = reactive({
        data:{
            "name": "",
        },
    })

    onMounted(() => {
        setTimeout(() => {
            proxy.$refs['form'].clearValidate()
        }, 0);
        init()
    })

    let init = async () => {
        getconfig()
    }

    let getconfig=()=>{
        proxy.$ajax({
            url: '/manager/config/get',
            data: {},
            bfLoading: true
        }).then(d => {
            console.log(d);
            
            if(d.success){
                obj.data.name = d.msg||''
            }
        }).catch(() => {})
    }

    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                proxy.$ajax({
                    url: '/manager/config/design',
                    data: obj.data,
                    bfLoading: true
                }).then(data => {
                    if(data.success){
                        proxy.elMessageMixin(`${obj.data.dept_id > 0 ? '保存' : '添加'}成功`, 'success')
                    }else{
                        ElMessage({ message: data.err, type: 'error', duration: 2 * 1000 })
                    }
                }).catch(() => {})
            } else {
                return false
            }
        })
    }
</script>

<style scoped>
    .el-form{max-width: 400px !important;}
</style>

